﻿namespace ClassLibrary.BusinessLayer.BusinessObjects
{
    using System;
    using System.Data;

    [AttributeUsage(AttributeTargets.All)]
    public class ClassPropertyAttribute : Attribute
    {
        private string _ColumnName;
        private DBTypes _DBType;
        private string _ParamName;
        private bool isChild;
        private bool isDelete;
        private bool isInsert;
        private bool isSelect;
        private bool isUpdate;

        public ClassPropertyAttribute(bool ischild, bool isinsert, bool isdelete, bool isupdate, bool isselect, string columnName, string paramName, DBTypes dbType)
        {
            this.isInsert = isinsert;
            this.isDelete = isdelete;
            this.isSelect = isselect;
            this.isUpdate = isupdate;
            this.isChild = ischild;
            this._ColumnName = columnName;
            this._ParamName = paramName;
            this._DBType = dbType;
        }

        public static DbType GetFieldConditionString(DBTypes c)
        {
            if (c == DBTypes.Integer)
            {
                return DbType.Int32;
            }
            if (c == DBTypes.Varchar)
            {
                return DbType.String;
            }
            if ((c == DBTypes.Date) | (c == DBTypes.DateTime))
            {
                return DbType.DateTime;
            }
            if (c == DBTypes.Decimal)
            {
                return DbType.Decimal;
            }
            return DbType.Guid;
        }

        public string ColumnName
        {
            get
            {
                return this._ColumnName;
            }
        }

        public DbType FieldType
        {
            get
            {
                return GetFieldConditionString(this._DBType);
            }
        }

        public bool IsChild
        {
            get
            {
                return this.isChild;
            }
        }

        public bool IsDelete
        {
            get
            {
                return this.isDelete;
            }
        }

        public bool IsInsert
        {
            get
            {
                return this.isInsert;
            }
        }

        public bool IsSelect
        {
            get
            {
                return this.isSelect;
            }
        }

        public bool IsUpdate
        {
            get
            {
                return this.isUpdate;
            }
        }

        public string ParamName
        {
            get
            {
                return this._ParamName;
            }
        }

        public enum DBTypes
        {
            Integer,
            Varchar,
            Date,
            DateTime,
            Decimal
        }
    }
}

